package pl.com.sthaether.mc.event;

import java.io.Serializable;

public abstract class MCEvent<T> implements Serializable {

    private String eventName;
    private MCEventType type;
    private boolean registerOnBus;

    protected MCEvent(String eventName, MCEventType type, boolean registerOnBus) {
        this.eventName = eventName;
        this.type = type;
        this.registerOnBus = registerOnBus;
    }

    public T resolveEvent() {
        T result = eventSteps();
        MCEventBus.getBus().registerEventDone(this);
        return result;
    }

    protected abstract T eventSteps();

    public String getName() {
        return eventName;
    }

    public MCEventType getType() {
        return type;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof MCEventListener) {
            return getName().equals(((MCEventListener) obj).getName());
        }
        return super.equals(obj);
    }
}
